#!/usr/bin/env python
#coding:utf-8
import pymysql,time,datetime
ltime=time.localtime(time.time()-300)
# print(time.time()-300)
datestrftime=time.strftime('%Y-%m-%d %H:%M:%S',ltime)
# print(datestrftime)

def select_mysql(sql):
    conn = pymysql.connect(host='127.0.0.1', user='root', passwd='763227lxk', db='zabbix',
                           charset='UTF8')

    cur = conn.cursor()
    reCount = cur.execute(sql)

    nRet = cur.fetchall()
    cur.close()

    conn.close()
    return nRet


def insert_mysql(sql):
    conn = pymysql.connect(host='121.201.68.21', port=3307, user='jiang', passwd='jiangwenhui', db='daxiangzhanshi',

                           charset='UTF8')

    cur = conn.cursor()

    cur.execute(sql)
    nRet = cur.fetchall()
    conn.commit()

    cur.close()

    conn.close()
    return nRet

if __name__ == "__main__":

    select = "SELECT SUM(value),itemid FROM zabbix.history_uint WHERE   clock>=%s and itemid in (32795) group by itemid"%(time.time()-300)
    data = select_mysql(select)
    print(data)

